package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.DPointDao;
import com.hongxun.modules.bss.entity.DPointEntity;
import com.hongxun.modules.bss.service.DPointService;



@Service("dPointService")
public class DPointServiceImpl implements DPointService {
	@Autowired
	private DPointDao dPointDao;
	
	@Override
	public DPointEntity queryObject(String guid){
		return dPointDao.queryObject(guid);
	}
	
	@Override
	public List<DPointEntity> queryList(Map<String, Object> map){
		return dPointDao.queryList(map);
	}
	@Override
	public List<DPointEntity> queryDxtList(DPointEntity dPoint){
		return dPointDao.queryDxtList(dPoint);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return dPointDao.queryTotal(map);
	}

	@Override
	public double queryWire(Map<String, Object> map){
		return dPointDao.queryWire(map);
	}

	@Override
	public void save(DPointEntity dPoint){
		if(dPoint.getGuid()==null||dPoint.getGuid().equals("")) {

			dPoint.setGuid(UUID.randomUUID().toString());
		}
		dPointDao.save(dPoint);
	}
	
	@Override
	public void update(DPointEntity dPoint){
		dPointDao.update(dPoint);
	}
	
	@Override
	public void delete(String guid){
		dPointDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		dPointDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<DPointEntity> entities) {
		for (DPointEntity d : entities) {
			if (d.getPPDatastate().equals("删除")) {
				dPointDao.delete(d.getGuid());
			} else {
				DPointEntity dPointEntity = dPointDao.queryObject(d.getGuid());
				if (dPointEntity == null) {
					dPointDao.save(d);
				} else {
					dPointDao.update(d);
				}
			}
		}
	}
}
